<template>
  <el-dialog
    v-model="visible"
    :title="`修改${form.info_type_name}`"
    width="600px"
    :before-close="handleClose"
  >
    <el-form  :model="form" label-width="120px" style="width: 88%">
      <el-form-item label="名称">
        <el-input v-model="form.info_name"></el-input>
      </el-form-item>
      <el-form-item label="备注">
        <el-input
          v-model="form.info_remark"
          type="textarea"
          :rows="3"
        ></el-input>
      </el-form-item>
    </el-form>

    <template #footer>
      <span class="dialog-footer">
        <el-button @click="visible = false">关闭</el-button>
        <el-button type="primary" @click="exec">确定</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup >
import { reactive, ref} from "vue";
import { tip, get, post, put, del, ddo } from "@/common";

const visible = ref(false);
const open = (type_code, type_name, item) => {
  form.info_id = item.info_id;
  form.info_type = type_code;
  form.info_type_name = type_name;
  form.info_name = item.info_name;
  form.info_remark = item.info_remark;
  visible.value = true;
};
const handleClose = (done) => {
  done();
};

const form = reactive({
  info_id: "",
  info_type: "",
  info_type_name: "",
  info_name: "",
  info_remark: "",
});

const emit = defineEmits(["ok"]);
const exec = () => {
  put("/info", form, { title: "提示", message: `您确定更新${form.info_type_name}吗？` }).then(
    (result) => {
      emit("ok");
      visible.value = false;
      tip.success(`更新${form.info_type_name}成功！`);
    }
  );
};

defineExpose({ open });
</script>

<style>
</style>